package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.dto.WmNewsPageReqDto;
import com.heima.model.wemedia.dto.WmNewsUpAndDownDto;
import com.heima.model.wemedia.pojo.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {


    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询文章
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult<List<WmNews>> findAll(@RequestBody WmNewsPageReqDto dto){
        return  wmNewsService.findAll(dto);
    }

    /**
     * 新增文章
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto){
        return  wmNewsService.submitNews(dto);
    }

    /**
     * 自媒体文章上下架功能
     * @param dto
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult upAndDown(@RequestBody WmNewsUpAndDownDto dto){
        //接收参数
        //调用service
        //返回结果
        return  wmNewsService.upOrDown(dto);
    }
}
